import { defaHttp, Api } from "../index";
/**创建房间 */
export async function apiCreateRoom(
  data: CreateRoom.Req
): Promise<CreateRoom.Res | undefined> {
  const res = await defaHttp.post<Api.Res<CreateRoom.Res>>(
    "/create/token",
    data,
    {
      mode: {
        successMessage: true,
        failMessage: true,
        loadingMessage: true,
      },
    }
  );
  console.log(res);

  if (!res.status) return;
  return res.data;
}
/**创建房间 */
export namespace CreateRoom {
  export interface Req {
    code: string;
  }
  export interface Res {
    token: string;
    user_id: string;
    gslb: string[];
    appid: string;
    timestamp: number;
    nonce: string;
    channel: number;
    turn: Turn;
  }
  export interface Turn {
    username: string;
    password: string;
  }
}

/**加入房间 */
export async function apiJoinRoom(
  data: JoinRoom.Req
): Promise<JoinRoom.Res | undefined> {
  const res = await defaHttp.post<Api.Res<JoinRoom.Res>>(
    "/join/channel",
    data,
    {
      mode: {
        successMessage: true,
        failMessage: true,
        loadingMessage: true,
      },
    }
  );
  if (!res.status) return;
  return res.data;
}
/**加入房间 */
export namespace JoinRoom {
  export interface Req {
    channel: string;
  }
  export interface Res extends CreateRoom.Res {}
}

/**删除房间 */
export async function apiDelRoom(
  data: DelRoom.Req
): Promise<DelRoom.Res | undefined> {
  const res = await defaHttp.post<Api.Res<DelRoom.Res>>(
    "/delete/channel",
    data,
    {
      mode: {
        failMessage: true,
      },
    }
  );

  if (!res.status) return;
  return res.data;
}
/**删除房间 */
export namespace DelRoom {
  export interface Req {
    channel: string;
  }
  export interface Res {}
}
